package com.internetCafes.spms.web.customer.service.impl.area;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.internetCafes.spms.common.utils.ShiroUtils;
import com.internetCafes.spms.web.customer.common.util.UserInfoUtil;
import com.internetCafes.spms.web.customer.entity.area.Area;
import com.internetCafes.spms.web.customer.mapper.area.AreaMapper;
import com.internetCafes.spms.web.customer.model.area.*;
import com.internetCafes.spms.web.customer.service.area.IAreaService;
import com.internetCafes.spms.web.sys.model.UserInfo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 区域表 服务实现类
 * </p>
 *
 * @author Zj
 * @since 2021-10-18
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements IAreaService {

    @Override
    public List<EntAreaPo> listPo(EntAreaDo areaDo) {
        return baseMapper.listPo(areaDo);
    }

    @Override
    public List<EntAreaManagerPo> getAreaInfoByManagerIdList(List<Long> managerIdList) {
        return baseMapper.getAreaInfoByManagerIdList(managerIdList);
    }

    @Override
    public EntAreaDetailPo getAreaDetailForSaleByAreaId(Long areaId) {
        return baseMapper.getAreaDetailForSaleByAreaId(areaId);
    }

    @Override
    public List<EntAreaDetailPo> listAreaDetailForSale(EntAreaDetailDo areaDetailDo) {
        return baseMapper.listAreaDetailForSale(areaDetailDo);
    }

    @Override
    public List<EntAreaDetailPo> listAreaDetailForManager(EntAreaDetailDo areaDetailDo) {
        return baseMapper.listAreaDetailForManager(areaDetailDo);
    }

    @Override
    public List<Area> listManagerOrSale() {
        UserInfo userEntity = ShiroUtils.getUserEntity();
        AreaManagerOrSaleResponsibleDo responsibleDo = new AreaManagerOrSaleResponsibleDo();
        if (!UserInfoUtil.entSuperAdminJudge(userEntity)) {
            responsibleDo.setUserId(userEntity.getId());
        }
        return baseMapper.listManagerOrSaleResponsible(responsibleDo);
    }

    @Override
    public List<Area> listNoTenantId(Wrapper<Area> queryWrapper) {
        return baseMapper.listNoTenantId(queryWrapper);
    }

    @Override
    public List<EntAreaPo> poList(EntAreaDo areaDo) {
        return baseMapper.poList(areaDo);
    }

    @Override
    public Map<String, List<Area>> areaGroupByName() {
        return list().stream().collect(Collectors.groupingBy(Area::getName));
    }

    @Override
    public List<EntAreaUserPagingPo> entAreaUserPoList(EntAreaUserPagingReq req) {
        return baseMapper.entAreaUserPoList(req);
    }

    @Override
    public List<EntSaleAreaListPo> saleAreaListPo(EntSaleAreaListDo saleAreaListDo) {
        return baseMapper.saleAreaListPo(saleAreaListDo);
    }

    @Override
    public EntAreaUserDetailPo entAreaUserPoDetail(Long id) {
        return baseMapper.entAreaUserPoDetail(id);
    }

    @Override
    public Page<EntAreaUserPagingPo> entAreaUserPoPaging(Page<Area> page, EntAreaUserPagingReq req) {
        return baseMapper.entAreaUserPoPaging(page, req);
    }

    @Override
    public Page<EntAreaPagingPo> entAreaPoPaging(Page<Area> page, Wrapper<Area> queryWrapper) {
        return baseMapper.entAreaPoPaging(page, queryWrapper);
    }
}
